﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="限制文本框输入数据类型.aspx.cs" Inherits="ProjectStudy.限制文本框输入数据类型" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        jQuery.fn.number = function () {
            this.bind("keypress", function (e) {
                var code = (e.keyCode ? e.keyCode : e.which); //兼容火狐 IE 
                //火狐下不能使用退格键 

                if (!$.browser.msie && (e.keyCode == 0x8)) { return; }
                if (this.value.indexOf(".") == -1) {

                    return (code >= 48 && code <= 57) || (code == 46);
                }
                else if (this.value.substring(this.value.indexOf(".")).length <= 2) {

                    return (code >= 48 && code <= 57);
                }
                else {
                    return false;
                }

            });
            this.bind("paste", function () { return false; });
            this.bind("keyup", function () {
                if (this.value.slice(0, 1) == ".") {
                    this.value = "";
                }
            });
            this.bind("blur", function () {
                if (this.value.slice(-1) == ".") {
                    this.value = this.value.slice(0, this.value.length - 1);
                }
            });

        };



        jQuery.fn.number2 = function () {
            this.bind("keypress", function (e) {
                var code = (e.keyCode ? e.keyCode : e.which); //兼容火狐 IE 
                //火狐下不能使用退格键 

                if (!$.browser.msie && (e.keyCode == 0x8)) { return; }


                return (code >= 48 && code <= 57);


            });
            this.bind("paste", function () { return false; });
            this.bind("keyup", function () {
                if (this.value.slice(0, 1) == ".") {
                    this.value = "";
                }
            });
            this.bind("blur", function () {
                if (this.value.slice(-1) == ".") {
                    this.value = this.value.slice(0, this.value.length - 1);
                }
            });
            this.focus(function () {

                this.style.imeMode = 'disabled';
            });


        };




        $().ready(function () {
            $("#ip1").number();
            $("#ip2").number2();
        });

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
    只能输入两位小数或整数
    <br />
    <input  type="text" id="ip1"/><br /><br />
    只能输入整数
    <br />
    <input  type="text" id="ip2"/>
    <br />
    <br />
    <input  type="text" id="ip3"/>
        <br />
        <br />
        <input type="text" onpaste="return false" ondragenter="return false" oncontextmenu="return false;" style="ime-mode:disabled"/>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="以事务方式调用存储过程" onclick="Button1_Click" />
        <br />
    </div>
    </form>
</body>
</html>
